<?php
/**
 * @Name
 * @Description
 * @Auther zsx
 * @Date 2023/2/28 09:43
 */

namespace app\service;


use app\common\BaseService;
use app\model\Department as DepartmentModel;

class DepartmentService extends BaseService
{
  public static function getInstance(): DepartmentService
  {
    return parent::getInstance();
  }

  public static function getModel(): DepartmentModel
  {
    return DepartmentModel::getInstance();
  }

  /*
   * 通过condition获取Department
   */
  public function getDepartmentByCondition($conditions = [], $order = ['id' => 'desc']) {
    $query = self::getModel();
    foreach ($conditions as $item) {
      list($field, $value, $op) = $item;
      if (!$op) {
        $op = '=';
      }
      $query = $query->where($field, $op, $value);
    }
    $query = $query->order($order);
    $result = $query->select()->toArray();
    return $result;
  }

}